package com.sumainfor.common.utlis;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * 功能描述:
 *
 * @Auther: zhlu
 * @Date: 2019/3/2 10:33
 * @Description:
 */
public class Ripper {
    public static void main(String[] args) {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("HouInfoId", "PYXY05932133214Z");
        map.put("Pricing", 13.14);

        Map<String, Object> map2 = new HashMap<String, Object>();
        map2.put("HouInfoId", "PYXY05932133214Z");
        map2.put("Pricing", 15.15);

        Map<String, Object> map3 = new HashMap<String, Object>();
        map3.put("HouInfoId", "PYXY05930123213B");
        map3.put("Pricing", 20.11);

        Map<String, Object> map4 = new HashMap<String, Object>();
        map4.put("HouInfoId", "FDXQ01213124213Z");
        map4.put("Pricing", 18.1);

        List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
        list.add(map);
        list.add(map2);
        list.add(map3);
        list.add(map4);

        Stream<Map<String, Object>> stream = list.stream();

        List<Map<String, Object>> list2 = stream.sorted(Ripper::comparator).collect(Collectors.toList());
        for (Map<String, Object> m : list2) {
            System.out.println(m.get("HouInfoId") + " " + m.get("Pricing"));
        }
    }

    public static int comparator(Map<String, Object> map1, Map<String, Object> map2) {
        if (map1 == null && map2 == null)
            return 0;

        if (map1 == null || map2 == null) {
            throw new NullPointerException();
        }

        String ActId1 = (String) map1.get("HouInfoId");
        String ActId2 = (String) map2.get("HouInfoId");
        int c = ActId2.compareTo(ActId1);
        if (c != 0)
            return c;

        int Pricing1 = (int)Double.valueOf(map1.get("Pricing").toString()).intValue();
        int Pricing2 = (int)Double.valueOf(map2.get("Pricing").toString()).intValue();

        return Pricing1 - Pricing2;
    }
}
